package models

import (
	"fmt"
	"github.com/golang/protobuf/proto"
	"kop/libs/redis"
	"kop/pb"
	"kop/util/date"
)

func GetRevenges(roleID int32) []int32 {

	var mess = pb.Int32Slice{Slices: make([]int32, 0)}

	if b, _ := redis.Get(fmt.Sprintf("Revenge%d", roleID)); b != nil {
		_ = proto.Unmarshal(b, &mess)
	}

	return mess.Slices
}

// roleID 进攻方, roleID2 防守方
func SaveRevenge(roleID, roleID2 int32) {

	var IDs = append(GetRevenges(roleID), roleID2)

	var b, _ = proto.Marshal(&pb.Int32Slice{Slices: IDs})
	if err := redis.Set(fmt.Sprintf("Revenge%d", roleID), b, date.TodayExpire()); err != nil {
		panic(err)
	}
}
